package com.muki.spider.core;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
@EnableScheduling
public class ContentMessageHandler {

	@Autowired private JmsMessagingTemplate jmsMessagingTemplate;
	
	@Scheduled(fixedRate=1000)
	public void handle() {
		while(true) {
			Map<String,String> message = null;
			try {
				message = ContentMessageParser.get();
				if(message!=null)
					jmsMessagingTemplate.convertAndSend("content-seen",message);
			} catch (InterruptedException e) {
				break;
			} 
		}
	}
	
}
